package com.gitee.hermer.engine.jars.core.xa.transaction.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import com.gitee.hermer.boot.jee.commons.number.IntegerUtils;
import com.gitee.hermer.engine.jars.core.domain.EngineConstant;
import com.gitee.hermer.engine.jars.dependent.dsm.domain.EngineProperties;

@PropertySource(EngineConstant.ENGINE_CONFIG_PROPERTIES_CLASS_PATH)
@Component
public class XATransactionProperties extends EngineProperties{

	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_XA_TRANSACTION_TIMEOUT)
	private  Integer tranTimeOut;
	
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_XA_TRANSACTION_ROLLBACK_ON_PARTICIPATION_FAILURE)
	private Boolean rollbackOnParticipationFailure;
	
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_XA_TRANSACTION_ALLOW_CUSTOM_IS_OLATION_LEVELS)
	private Boolean allowCustomIsolationLevels;
	
	public Integer getTranTimeOut() {
		return IntegerUtils.defaultIfZero(tranTimeOut, EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_XA_TRANSACTION_TIMEOUT);
	}
	public void setTranTimeOut(Integer tranTimeOut) {
		this.tranTimeOut = tranTimeOut;
	}
	
	public Boolean getAllowCustomIsolationLevels() {
		return allowCustomIsolationLevels == null?EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_XA_TRANSACTION_ALLOW_CUSTOM_IS_OLATION_LEVELS:allowCustomIsolationLevels;
	}
	
	public Boolean getRollbackOnParticipationFailure() {
		return rollbackOnParticipationFailure == null?EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_XA_TRANSACTION_ROLLBACK_ON_PARTICIPATION_FAILURE:rollbackOnParticipationFailure;
	}
	public void setAllowCustomIsolationLevels(Boolean allowCustomIsolationLevels) {
		this.allowCustomIsolationLevels = allowCustomIsolationLevels;
	}
	public void setRollbackOnParticipationFailure(Boolean rollbackOnParticipationFailure) {
		this.rollbackOnParticipationFailure = rollbackOnParticipationFailure;
	}
	
}
